<?php

require_once './include/common.inc.php';
require_once 'left.php';
require_once 'right.php';

$page_title = 'Acuity World WebShop';
$menu_id = 0;
$menu_str = PrintMenu();

$deliver = 0;
$error_msg = '';

if ($_POST['act'] == "send") {
    //$username = $_POST['username'];
    $email = $_POST['email'];

/*    if (empty($username)) {
        echo "<script>alert('You didn't specify a valid Username');history.back();</script>";
        exit;
    }*/
    
    if (!preg_match("/[a-z0-9\.]{2,}@[a-z0-9]{2,}\.[a-z0-9]+/", $email)) {
        echo "<script>alert('Invalid To Email, Please try again');history.back();</script>";
        exit;
    }

    
    $sql = "SELECT `firstname`, `lastname`, `password2` FROM `cus_members` WHERE `email` = '$email' ";
    $user_info_ary = $db->get_one($sql);
    
    if (!empty($user_info_ary)) {
        $username = empty($user_info_ary['lastname']) ? $user_info_ary['firstname'] : $user_info_ary['firstname'] . ' ' . $user_info_ary['lastname'];
        
        require_once './mail/member_forgot_password.php';
        sendhtmlmail($from_name,$from_email,$to_name,$to_email,$subject,$content);
        
        header("location:member_forgot_password.php?email=$email&succeed");
        exit;    
    } else {
        $error_msg = "<font style='color:#FF0000'>You have specified a valid Email Address</font>";
    }
    
    
}

if (isset($_GET['succeed'])) {
    $deliver = 1;
    $email = $_GET['email'];
}

require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('member_forgot_password');
require_once PrintEot('right');
require_once PrintEot('footer');

?>